package com.china08.yxyapi.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.AsyncRestTemplate;
import org.springframework.web.client.RestTemplate;

import com.china08.yxyapi.security.BasicAuthorizationInterceptor;

@Configuration
public class RestTemplateConfig {

    @Value("${yx.rest.service.appid}")
    private String yxRestServiceAppid;

    @Value("${yx.rest.service.appsecret}")
    private String yxRestServiceAppsecret;

    @Bean
    RestTemplate restTemplate() {
        return new RestTemplate();
    }

    @Bean(name = "templateForYxServer")
    RestTemplate getForYxServe() {
        RestTemplate restTemplate = new RestTemplate();
        restTemplate.getInterceptors()
                .add(new BasicAuthorizationInterceptor(yxRestServiceAppid, yxRestServiceAppsecret));
        return restTemplate;

    }

    @Bean(name = "templateAsyncForYxServer")
    AsyncRestTemplate getAsyncYxServe() {
        AsyncRestTemplate asyncRestTemplate = new AsyncRestTemplate();
        return asyncRestTemplate;
    }

}
